﻿namespace Guia.Elements
{
    using System.Windows.Automation;
    using Guia.Elements.PatternServants;
    using Guia.Locator;

    /// <summary>
    /// This class represents a button.
    /// </summary>
    public class Button : UiElement, IInvoke
    {
        /// <summary>
        /// Represents a helper-servant for the Invoke-pattern.
        /// </summary>
        private readonly IInvoke invokeServant;
        
        /// <summary>
        /// Initializes a new instance of the Button class. 
        /// </summary>
        /// <param name="automationElement">The AutomationElement representating the Button.</param>
        public Button(AutomationElement automationElement)
            : base(automationElement)
        {
            this.invokeServant = new InvokeImpl(this);
        }

        /// <summary>
        /// Gets the default-condition to find a control by its type.
        /// </summary>
        public static SearchCondition ControlTypeCondition
        {
            get { return SearchCondition.ByControlType(ControlType.Button); }
        }

        /// <summary>
        /// Gets the Buttons TextValue
        /// </summary>
        public string TextValue
        {
            get { return Name; }
        }

        /// <summary>
        /// Invokes the Button
        /// </summary>
        public void Invoke()
        {
            this.invokeServant.Invoke();
        }
    }
}
